<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>会员列表</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0"/>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css">
    <%--<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css">--%>
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/chosen/chosen.css"/>
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
    <link href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css" rel="stylesheet">
    <style type="text/css">
        body {
            font-size: 14px;
        }

        .dataTables_info {
            font-size: 12px
        }

        .dataTables_paginate {
            font-size: 12px;
        }

        .searchCondition a {
            color: black;
        }

        .searchCondition a:last-child {
            margin-right: 0;
        }

        .searchCondition a.cfoucs {
            color: #1ab394;
            font-weight: bold;
        }

        .radio-primary input[type="radio"] + label::after {
            background-color: #1ab394;
        }

        .radio-primary input[type="radio"]:checked + label::after {
            background-color: #1ab394;
        }

        .radio-primary input[type="radio"]:checked + label::before {
            border-color: #1ab394;
        }
        .searchCondition div.row{margin-bottom: 8px;}
        #score {
            width:350px !important;
        }
        .input-checkbox{
            vertical-align:middle !important;
        }
        .checkbox input[type=checkbox] {
            margin-top: 5px !important;
            margin-left: -13px !important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-fluid">
    <div class="row searchCondition" style="background-color: white;padding: 10px;">
        <div class="row">
            <div class="col-sm-3">
                门店选择
                <input id="store_name" placeholder="请输入门店名称" class="form-control chosen-select" style="width: 160px;display: inline-block;">
            </div>
            <div class="col-sm-3">
                所属客户代表
                <input id="market_name" class="form-control" style="width: 160px;display: inline-block;">
            </div>
            <div class="col-sm-3">
                会员电话
                <input id="phone" type="text" class="form-control" placeholder="请输入会员手机号" style="width: 160px;display: inline-block;">
            </div>
            <div class="col-sm-3 text-right">
                <button onclick="func_dataTableReload()" class="btn btn-primary" type="button">查询</button>
                <button onclick="func_advancedSearch()" class="btn btn-primary" style="background-color: rgba(92, 138, 215, 1)" type="button">高级搜索</button>
            </div>
            <!--             <div class="col-sm-2 text-right"> -->
            <!--                 <a style="color: #1ab394;display: none;" onclick="pieShowOrHide(this)">自定义筛选条件</a> -->
            <!--             </div> -->
        </div>
        <div class="row" style="line-height: 40px;">
            <div class="col-sm-3 jfoucs" style="width: 220px;height: 30px;line-height: 30px;">
                最近购买时间：<a class="cfoucs" last_time="0" style=" margin-right: 12px;">不限</a><a last_time="">自定义</a>
            </div>
            <div class="col-sm-3" style="padding: 0;height: 40px;display: none;" id="data_5">
                <div class="input-daterange input-group" id="datepicker">
                    <input type="text" class="input-sm form-control" name="start" value="2017-01-01" id="starttime">
                    <span class="input-group-addon" style="height: 24px;">到</span>
                    <input type="text" class="input-sm form-control" name="end" value="2017-12-31" id="endtime">
                </div>
            </div>
            <div class="col-sm-1">
            </div>
            <div class="col-sm-5 jfoucs" id="score">
                积分：<a class="cfoucs" point="0"  style=" margin-right: 12px;">不限</a><a point="">自定义</a>
                <span id="custPoint" style="display: none;">
	            <input id="point1" type="number" class="form-control" style="width: 80px;display: inline-block;">
	            	至
	            <input id="point2" type="number" class="form-control" style="width: 80px;display: inline-block;">
	            </span>
            </div>
            <div class="col-sm-3 jfoucs" style="width: 220px;height: 30px;line-height: 30px;">
                注册时间：<a class="cfoucs" register_time="0" style=" margin-right: 12px;">不限</a><a register_time="" onclick="registerTime()">自定义</a>
            </div>
            <div class="col-sm-3" style="padding: 0;height: 40px;display: none;" id="data_6">
                <div class="input-daterange input-group" id="datepicker">
                    <input type="text" class="input-sm form-control" name="start" value="2017-01-01" id="register_starttime">
                    <span class="input-group-addon" style="height: 24px;">到</span>
                    <input type="text" class="input-sm form-control" name="end" value="2017-12-31" id="register_endtime">
                </div>
            </div>
        </div>
        <div class="row" id="advanced-search" style="line-height: 40px;display: none;">
            <img alt="" style="position: absolute;left: 0px;width: 854px;height: 2px;" src="<%=path%>/images/member/top_line.png">
            <div class="col-sm-3">
                <img src="<%=path%>/images/member/sex.png" style="width: 26px;height: 26px">
                性别：<select id="sex-id" style="height: 22px;width: 84px">
                <option value="">不限</option>
                <option value="m">男</option>
                <option value="f">女</option>
                <option value="n">未获取</option>
            </select>
            </div>
            <div class="col-sm-3">
                <img src="<%=path%>/images/member/member_level.png" style="width: 26px;height: 26px">
                会员等级：<select id="member_level" style="height: 22px;width: 84px">
                <option value="">不限</option>
                <option value="金牌">金牌</option>
                <option value="普通会员">普通会员</option>
                <option value="一级">一级会员</option>
                <option value="高级会员">高级会员</option>
                <option value="白金会员">白金会员</option>
                <option value="钻石会员">钻石会员</option>
                <option value="n">无等级</option>
            </select>
            </div>
            <div class="col-sm-3 jfoucs" style="width: 440px">
                <img src="<%=path%>/images/member/cost_count.png" style="width: 26px;height: 26px">
                购买次数：<a class="cfoucs" cost-count-point="0"  style=" margin-right: 12px;">不限</a><a cost-count-point="">自定义</a>
                <span id="cust-count" style="display: none;">
	            <input id="cost-count-start" class="form-control" onkeyup="value=value.replace(/[^\d]/g, '')" oninput="if(value.length>6)value=value.slice(0,6)" style="width: 80px;display: inline-block;">
	            	至
	            <input id="cost-count-end" onkeyup="value=value.replace(/[^\d]/g, '')" oninput="fun_onInput()" class="form-control" style="width: 80px;display: inline-block;">
	            </span>
            </div><br>
            <div style="height: 40px;">
                <img alt="" style="position: absolute;left: 0px;width: 1257px;" src="<%=path%>/images/member/center_line.png">
                <img alt="" style="margin-left:15px;width: 19px;height: 19px;" src="<%=path%>/images/member/describe.png">
                <span>筛选规则说明：以上筛选条件为并行筛选关系</span>
                <button class="btn btn-primary" onclick="func_advancedSearch()" style="float: right;margin-right: 20px;margin-top: 5px;width: 112px;height: 30px;background-color: rgba(92, 138, 215, 1)" type="button">收起</button>
                <img alt="" style="margin-top:-35px;width: 100%;height: 2px;" src="<%=path%>/images/member/down_line.png">
            </div>
        </div>
    </div>
    <div class="row" style="margin-top:10px;background-color: white;padding: 10px 0;">
        <div class="col-sm-4">
            <!--             <div class="input-group"> -->
            <!--                 <input id="phone" type="text" class="form-control" placeholder="请输入会员手机号"> <span -->
            <!--                     class="input-group-btn"> -->
            <!-- 	            <button onclick="func_dataTableReload()" type="button" class="btn btn-primary">搜索</button> </span> -->
            <!--             </div> -->
        </div>
        <div class="col-sm-8 text-right">
            <button data-toggle="modal" data-target="#myModal" onclick="member.drawMemberShowColumn('<%=path%>')" class="btn btn-primary" type="button">显示字段</button>
            <shiro:hasPermission name="member_list:import">
                <button onclick="memberImport();" class="btn btn-primary" type="button" id="importButton">导入会员</button>
            </shiro:hasPermission>
            <shiro:hasPermission name="smember_list:create">
                <button onclick="func_showSaveMemberDialog()" class="btn btn-primary" type="button">新建会员</button>
            </shiro:hasPermission>
            <shiro:hasPermission name="member_list:export">
                <button onclick="func_exportMember(this)" id="exportBtn" class="btn btn-primary" type="button">导出会员</button>
            </shiro:hasPermission>
            <shiro:hasPermission name="member_list:show_field">
                <button class="btn btn-primary" style="display: none;" type="button">显示/隐藏列</button>
            </shiro:hasPermission>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <table id="myTable" class="display">
                <thead>
                <tr id="table-title">
                    <th>手机号码</th>
                    <th>姓名</th>
                    <th>等级</th>
                    <th>储值</th>
                    <th>所属门店</th>
                    <th>所属客户代表</th>
                    <th>最近购买时间</th>
                    <th>积分</th>
                    <!-- 					<th>性别</th> -->
                    <!-- 					<th>省份</th> -->
                    <!-- 					<th>城市</th> -->
                    <!-- 					<th>购买次数</th> -->
                    <!-- 					<th>购买件数</th> -->
                    <th style="width: 100px;">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<div style="display: none;">
    <div id="saveMemberDailog">
        <form method="get" class="form-horizontal">
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">会员手机号：</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control phone" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">会员姓名：</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control name">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">会员生日：</label>
                    <div class="col-sm-2">
                        <select class="form-control year" onchange="func_getDay()">
                        </select>
                    </div>
                    <div class="col-sm-1" style="padding-left:0;">
                        <span style="line-height:34px;">年</span>
                    </div>
                    <div class="col-sm-2">
                        <select class="form-control month" onchange="func_getDay()">
                        </select>
                    </div>
                    <div class="col-sm-1" style="padding-left:0;">
                        <span style="line-height:34px;">月</span>
                    </div>
                    <div class="col-sm-2">
                        <select class="form-control day">
                        </select>
                    </div>
                    <div class="col-sm-1" style="padding-left:0;">
                        <span style="line-height:34px;">日</span>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">会员性别：</label>
                    <div class="col-sm-1">
                        <div class="radio radio-primary">
                            <input id="a" type="radio" name="sex" value="m" checked="checked">
                            <label for="a">男</label>
                        </div>
                    </div>
                    <div class="col-sm-1">
                        <div class="radio radio-primary">
                            <input id="b" type="radio" name="sex" value="f">
                            <label for="b">女</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">QQ号码：</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control QQ">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">会员类别：</label>
                    <div class="col-sm-2">
                        <div class="radio radio-primary">
                            <input id="c" type="radio" name="status" value="2" checked="checked">
                            <label for="c">潜客</label>
                        </div>
                    </div>
                    <div class="col-sm-2">
                        <div class="radio radio-primary">
                            <input id="d" type="radio" name="status" value="1">
                            <label for="d">会员</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-2 control-label">备注：</label>
                    <div class="col-sm-9">
                        <textarea style="width: 100%;height: 100px;" class="form-control remarks"></textarea>
                    </div>
                </div>
            </div>
            <div class="row text-center" style="margin-top:20px;">
                <shiro:hasPermission name="member_list:update">
                    <button class="btn btn-primary" type="button" onclick="func_saveMember()">保存</button>
                </shiro:hasPermission>
            </div>
        </form>
    </div>
</div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
<script src="<%=path%>/js/member/memberList.js"></script>
<script type="text/javascript">
    $.fn.dataTable.ext.errMode = 'none';
    var path = "<%=path%>";
    var myDataTable;
    var saveMemberDialog = null;
    var importMemberDialog = null;
    var memberDetailDialog = null;
    var paramJsonObj={};
    var exportStatus = 0;	//会员导出状态
    var exportLoop = null;	//会员导出循环器
    var memberList = null; //会员列表


    $(function () {

        func_getYear();
        func_getMonth();
        func_getDay();

        $("#data_5 .input-daterange").datepicker({keyboardNavigation: !1, forceParse: !1, autoclose: !0});
        $("#data_6 .input-daterange").datepicker({keyboardNavigation: !1, forceParse: !1, autoclose: !0});

        $(".jfoucs a").click(function(){
            $(this).addClass("cfoucs").siblings().removeClass("cfoucs");

            if($(this).attr("last_time") != undefined){
                if($(this).attr("last_time") == ""){
                    $("#data_5").show();
                }else{
                    $("#data_5").hide();
                }
            }else if($(this).attr("point") != undefined){
                if($(this).attr("point") == ""){
                    $("#custPoint").show();
                }else{
                    $("#custPoint").hide();
                }
            }
            if($(this).attr("cost-count-point") != undefined){
                if($(this).attr("cost-count-point") == ""){
                    $("#cust-count").show();
                }else{
                    $("#cust-count").hide();
                }
            }
            if($(this).attr("register_time") != undefined){
                if($(this).attr("register_time") == ""){
                    $("#data_6").show();
                }else{
                    $("#data_6").hide();
                }
            }
//     		func_dataTableReload();
        });

        init();
        //初始化导入按钮的状态
        initImportButton();
        //定时更新节点状态
        importTime();

    });

    //键盘抬起事件
    function fun_onInput() {
        var cost_count_start = $("#cost-count-start").val();
        var cost_count_end = $("#cost-count-end").val();
        if ($("#cost-count-end").val().length > 6){
            $("#cost-count-end").val(cost_count_end.slice(0,6));
        }
        if(cost_count_start != "" && cost_count_end != ""){
            if (parseInt(cost_count_start) > parseInt(cost_count_end)){
                var d = dialog({
                    align: 'right',
                    content: '第二个值应比第一个值大'
                }).show($("#cost-count-end")[0]);
                setTimeout(function () {
                    d.close().remove();
                }, 1600);
            }
        }

    }

    //注册默认时间
    function registerTime() {
        var nowdate = new Date();
        var oneMonthDate = new Date(nowdate - 31*24*3600*1000);
        var y = oneMonthDate.getFullYear();
        var m = oneMonthDate.getMonth()+1;
        var d = oneMonthDate.getDate();
        var oneMonth = y+'-'+m+'-'+d;
        $("#register_starttime").datepicker("setDate",oneMonth);
        var oneDay = new Date(nowdate - 24*3600*1000);
        var year = oneDay.getFullYear();
        var month = oneDay.getMonth()+1;
        var day = oneDay.getDate();
        var yesterday = year+'-'+month+'-'+day;
        $("#register_endtime").datepicker("setDate",yesterday);
    }

    //测试大文件导入
    function memberImport(){
        var cid=$.cookie('cid');
        paramJsonObj.tenantId = cid;
        var paramJsonStr=JSON.stringify(paramJsonObj);
        paramJsonStr=encodeURI(paramJsonStr);
        var downloadTemplate = path+"/excel/memberData.csv";
        var beanName = "memberImportOperator";
        dataImportDialog = dialog({
            width: 600,
            height: 400,
            title: '会员导入',
            url: path + "/view/member/member/importMemberAsyn?downloadTemplate="+downloadTemplate+"&beanName="+beanName+"&paramJsonStr="+paramJsonStr+"&extensions=csv"
        });
        dataImportDialog.showModal();
    }


    function init() {
        //获取门店
        /*$.post(path + "/scan/member/listStore",function(data){
            if(data.msg_code == 1){
                var option = "";
                $.each(data.data,function(i,d){
                    option += '<option value="'+d.id+'">'+d.name+'</option>';
                });
// 	    		$(".chosen-select").append(option);
// 	    		var config = {
// 	            		".chosen-select":{},
// 	            		".chosen-select-deselect":{allow_single_deselect:!0},
// 	            		".chosen-select-no-single":{disable_search_threshold:10},
// 	            		".chosen-select-no-results":{no_results_text:"Oops, nothing found!"},
// 	            		".chosen-select-width":{width:"95%"}
// 	            };
// 	            for(var selector in config){
// 	            	$(selector).chosen(config[selector]);
// 	            }
            }
        },"json");*/

        myDataTable = dataTable();
        func_exportStatus();
    }

    function func_getYear() {
        var now = new Date();
        var startYear = 1900;
        var endYear = now.getFullYear();

        var option = "";
        for (; startYear <= endYear; startYear++) {
            option += '<option value="' + startYear + '">' + startYear + '</option>';
        }
        $(".year").html(option);
    }

    function func_getMonth() {
        var option = "";
        for (var i = 1; i <= 12; i++) {
            option += '<option value="' + i + '">' + i + '</option>';
        }
        $(".month").html(option);
    }

    function func_getDay() {
        var year = $(".year:last").val();
        var month = $(".month:last").val();

        var now = new Date();
        now.setFullYear(year);
        now.setDate(1);
        now.setMonth(month);
        now.setDate(0);
        var lastDay = now.getDate();

        var option = "";
        for (var i = 1; i <= lastDay; i++) {
            option += '<option value="' + i + '">' + i + '</option>';
        }
        $(".day:last").html(option);
    }

    function func_showSaveMemberDialog() {
        var windowHeight = $(window).height();
        var height = 455;
        if(windowHeight < 455){
            height = windowHeight;
        }
        saveMemberDialog = dialog({
            id:"saveMemberDialog",
            fixed:true,
            width: 800,
            height: height,
            title: '添加会员',
            url: path + "/view/member/member/memberSave"
//             content: $("#saveMemberDailog").html()
        });
        saveMemberDialog.showModal();
//         $("div[aria-labelledby='title:saveMemberDialog'] table div[i='content']").css("overflow-x", "hidden")//.css("overflow-y","auto");
        $("iframe[name='saveMemberDialog']:visible").attr("scrolling", "auto").css("overflow-x", "hidden").css("overflow-y", "auto");

        $(":radio[name='sex'][id='a']:last").attr("id","a2").next().attr("for", "a2");
        $(":radio[name='sex'][id='b']:last").attr("id","b2").next().attr("for", "b2");
        $(":radio[name='status'][id='c']:last").attr("id","c2").next().attr("for", "c2");
        $(":radio[name='status'][id='d']:last").attr("id","d2").next().attr("for", "d2");
    }

    //会员添加
    function func_saveMember() {
        var phone = $(".phone:last").val();
        var year = $(".year:last").val();
        var month = $(".month:last").val();
        var day = $(".day:last").val();
        var sex = $(":radio[name='sex']:checked:last").val();
        var QQ = $(".QQ:last").val();
        var status = $(":radio[name='status']:checked:last").val();
        var name = $(".name:last").val();
        var remarks = $(".remarks:last").val();

        if ($.trim(phone) == "") {
            alert("手机号码不能为空");
            return;
        }
        if (!/^1[34578]\d{9}$/.test($.trim(phone))) {
            alert("手机号码不正确");
            return;
        }

        var jsonObject = {};
        jsonObject.phone = phone;
        jsonObject.birthday = year + "-" + month + "-" + day;
        jsonObject.sex = sex;
        jsonObject.QQ = QQ;
        jsonObject.status = status;
        jsonObject.name = name;
        jsonObject.remarks = remarks;

        saveMemberDialog.remove();

        $.ajax({
            contentType: 'text/plain;charset=utf-8',
            dataType: 'json',
            type: 'POST',
            url: path + "/member/ajaxMemberSave",
            data: JSON.stringify(jsonObject),
            success: function (data) {
                if(data.msg_code == 0){
                    alert("插入失败");
                }else if(data.msg_text != null){
                    alert(data.msg_text);
                }else{
                    func_dataTableReload();
                }
            }
        });
    }

    function func_showImportMemberDialog() {
        importMemberDialog = dialog({
            width: 400,
            height: 300,
            title: '导入会员',
            url: path + "/view/member/member/importMember"
        });
        importMemberDialog.showModal();
    }

    function func_showMemberDetailDialog(memberId) {
        memberDetailDialog = dialog({
            id: "memberDetailDialog",
            fixed: true,
            width: 900,
            height: 400,
            title: '会员详情',
            url: path + "/view/member/member/memberDetail?memberId=" + memberId,
            cancel: true,
            cancelValue: "关闭"
        });
        memberDetailDialog.showModal();
        $("iframe[name='memberDetailDialog']:visible").attr("scrolling", "auto").css("overflow-x", "hidden").css("overflow-y", "auto");
    }

    function func_dataTableReload() {
        if(func_valid()){
            myDataTable.ajax.reload();
        }
    }

    //高级搜索条件
    function func_advancedSearch(){
        $("#advanced-search").toggle();
    }


    function func_AjaxUrl() {
        return path + "/member/ajaxMemberPageList";
    }

    function func_columns() {
        var arr = member.get_member_property('<%=path%>');
        var html_ = "";
        var jsonArr = [];
        if (arr != null){
            /*$("#table-title").hide();*/
            if (arr != null && arr.length > 0){
                for(i = 0,len=arr.length; i < len; i++) {
                    jsonArr.push({"data":arr[i].key});
                    if (i != len-1) {
                        html_ += '<th>'+arr[i].name+'</th>'
                    }
                }
                html_ += '<th style="width: 100px;">操作</th>'
                $("#table-title").html(html_);
            }
        }else{
            jsonArr = [
                {"data": "phone"},
                {"data": "name"},
                {"data": "crmMemberLevel"},
                {"data": "crmBalance"},
                {"data": "storeName"},
                {"data": "marketName"},
                {"data": "lastCostTime"},
                {"data": "crmScore"},
                {"data": "id"}
            ];
        }
        member.columnNum = jsonArr.length;
        return jsonArr;
    }

    //请求参数
    function func_ajaxData() {
        var jsonObject = new Object();
        if ($.trim($("#phone").val()) != "") {
            jsonObject.phone = $("#phone").val();
        }
//         if($(".chosen-select option:selected").text() != "请选择"){
//         	jsonObject.store_name = $(".chosen-select option:selected").text();
//         }
        if($.trim($("#store_name").val()) != ""){
            jsonObject.store_name = $.trim($("#store_name").val());
        }
        if($.trim($("#market_name").val()) != ""){
            jsonObject.market_name = $.trim($("#market_name").val());
        }
        if($("a[last_time].cfoucs").attr("last_time") == ""){
            jsonObject.lastCostTime1 = $("#starttime").val()+" 00:00:00";
            jsonObject.lastCostTime2 = $("#endtime").val()+" 23:59:59";
        }
        if($("a[register_time].cfoucs").attr("register_time") == ""){
            jsonObject.startCreateTime = $("#register_starttime").val()+" 00:00:00";
            jsonObject.endCreateTime = $("#register_endtime").val()+" 23:59:59";
        }
        if($("a[point].cfoucs").attr("point") == ""){
            if($("#point1").val() != ""){
                jsonObject.point1 = parseInt($("#point1").val())*100;
            }
            if($("#point2").val() != ""){
                jsonObject.point2 = parseInt($("#point2").val())*100;
            }
        }
        if($.trim($("#sex-id").val()) != ""){
            jsonObject.gender = $("#sex-id").val();
        }
        if($.trim($("#member_level").val()) != ""){
            jsonObject.crmMemberLevel = $("#member_level").val();
        }
        if($("a[cost-count-point].cfoucs").attr("cost-count-point") == ""){
            if($("#cost-count-start").val() != ""){
                jsonObject.costCountStart = parseInt($("#cost-count-start").val());
            }
            if($("#cost-count-end").val() != ""){
                jsonObject.costCountEnd = parseInt($("#cost-count-end").val());
            }
        }
        return jsonObject;
    }

    function dataTable() {
        return $('#myTable').DataTable({
            processing: true,
            ordering: false,
            searching: false,
            info: true,
            autoWidth: false,
            lengthChange: false,
            language: {
                emptyTable: '没有数据表',
                info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
                infoEmpty: '没有数据',
                lengthMenu: '每页显示 _MENU_ 条记录',
                loadingRecords: '正在加载数据....',
                processing: '正在处理数据....',
                zeroRecords: '没有找到匹配的记录',
                paginate: {
                    first: '首页',
                    previous: '前页',
                    next: '后页',
                    last: '尾页'
                }
            },
            order: [[1, 'desc']],
            pageLength: 10,
            pagingType: 'full_numbers',
            columns: func_columns(),
            columnDefs : [{
                render: function (data, type, full,meta) {
                        var result = "";
                        <shiro:hasPermission name="member_list:show">
                        result += '<button onclick="func_showMemberDetailDialog(\'' + data + '\')" class="btn btn-primary" type="button">查看</button>&nbsp;';
                        </shiro:hasPermission>
            //                     result += '<button onclick="func_showMemberDetailDialog(\'996888439976759296\')" class="btn btn-primary" type="button">查看</button>&nbsp;';
            //                     result += '<button onclick="func_synMember(' + data + ')" class="btn btn-primary" type="button">同步</button>';
                        return result;
                    },
                    targets: member.columnNum - 1
                }
            ],
            serverSide: true,
            ajax: {
                contentType: 'application/json;charset=utf-8',
                type: 'POST',
                url: func_AjaxUrl(),
                data: function (d) {
                    d.extra_search = func_ajaxData();
                    return JSON.stringify(d);
                }
            }
        });
    }

   function func_columnDefs(){
       var columnDefs = "";
       for(i = 0 , len = member.columnNum; i< len; i++){
           var b=len-1  ;
           var json= "{\"render\": function (data, type, full,meta) {"
                   if(b==i){
                       json+=" console.log(1111111);"

                       json+=" return '';"
                   }else{
                       json+="console.log(222222);"

                       json+="return member.dealData(meta.settings.aoColumns["+ i +"].data,data);"
                   }
           json+=" }, \"targets\": "+i+" },"
           columnDefs+=json;
       }
       columnDefs=columnDefs.substring(0,columnDefs.length-1)+"";
       <%--columnDefs.push(--%>
           <%--{--%>
               <%--render: function (data, type, full,meta) {--%>
                   <%--var result = "";--%>
                   <%--<shiro:hasPermission name="member_list:show">--%>
                   <%--result += '<button onclick="func_showMemberDetailDialog(\'' + data + '\')" class="btn btn-primary" type="button">查看</button>&nbsp;';--%>
                   <%--</shiro:hasPermission>--%>
<%--//                     result += '<button onclick="func_showMemberDetailDialog(\'996888439976759296\')" class="btn btn-primary" type="button">查看</button>&nbsp;';--%>
<%--//                     result += '<button onclick="func_synMember(' + data + ')" class="btn btn-primary" type="button">同步</button>';--%>
                   <%--return result;--%>
               <%--},--%>
               <%--targets: member.columnNum--%>
           <%--}--%>
       <%--);--%>

       var str = JSON.stringify(columnDefs);
       var str1 = JSON.parse(str);
       console.log(str1)

       return str1;
   }

    //验证
    function func_valid(){
        var point1 = $("#point1").val();
        var point2 = $("#point2").val();
        var cost_count_start = $("#cost-count-start").val();
        var cost_count_end = $("#cost-count-end").val();
        if($("a[point]:last").hasClass("cfoucs") && point1!='' && point2!=''){
            point1 = parseInt(point1);
            point2 = parseInt(point2);
            if(point1 > point2){
                var d = dialog({
                    align: 'right',
                    content: '第二个值应比第一个值大'
                }).show($("#point2")[0]);
                setTimeout(function () {
                    d.close().remove();
                }, 1600);
                return false;
            }
        }
        if (cost_count_start != "" && cost_count_end != ""){
            if (parseInt(cost_count_start) > parseInt(cost_count_end)){
                var d = dialog({
                    align: 'right',
                    content: '第二个值应比第一个值大'
                }).show($("#cost-count-end")[0]);
                setTimeout(function () {
                    d.close().remove();
                }, 1600);
                return false;
            }
        }
        return true;
    }

    /*============================================== 导出会员 ===================================================*/
    function func_exportMember(that){
        if(exportStatus == "0"){
            $.post(path+"/member/dealExportMember",function(){
                func_exportStatus();
            });
        }else if(exportStatus == "1"){

        }else{
            $("#exportBtn").attr("disabled",true);
            var url = path + "/member/exportMember";
            window.open(url);
            setTimeout(func_exportStatus,2000);
        }
    }
    //导出状态
    function func_exportStatus(){
        $.post(path+"/member/exportStatus",function(data){
            if(data.status == "200"){
                exportStatus = data.data;
                if(data.data == "0"){
                    $("#exportBtn").removeAttr("disabled");
                    $("#exportBtn").text("导出会员")
                }else if(data.data == "1"){
                    $("#exportBtn").text("下载中")
                    if(exportLoop == null){
                        exportLoop = setInterval(func_exportStatus,5000);
                    }
                }else{
                    clearTimeout(exportLoop);
                    exportLoop = null;
                    $("#exportBtn").text("下载")
                }
            }
        },"json")
    }

    /*============================================== 导入会员 ===================================================*/

    //上传文件成功提示
    function alertImportMember(){
        swal({title: "会员数据已上传！",text: "请耐心等待数据入库，谢谢。",type: 'success'}).then(function () {
            //用户点击确定后刷新页面
            location.reload();
        });
    }

    //初始化导入按钮的状态
    function initImportButton(){
        var cid=$.cookie('cid');
        $.ajax({
            type: "POST",
//             async: false,
            url: "${pageContext.request.contextPath}/member/initImportBtn",
            data: {"cid" : cid},
            dataType: "json",
            timeout: 1000,
            success: function(data){
                if(data.status == 200){
                    data = data.data;
                    //从redis中获取导入状态，导入中为0，导入完毕为1
                    //如果导入状态为1,那么,设置导入会员按钮为生效
                    //如果导入状态为0,那么，设置导入会员按钮为失效
                    if(data.importState == 0){
                        $("#importButton").atftr("disabled", true);
                        $("#importButton").text("正在导入");
                    }else if(data.importState == 1){
                        $("#importButton").attr("disabled", false);
                        $("#importButton").text("导入会员");
                    }
                }
            }
        });
    }
    //定时执行
    function importTime(){
        //每隔一分钟刷新下导入状态
        window.setInterval(initImportButton,1000*60*0.5);//这里的1000表示1秒有1000毫秒,1分钟有60秒,1表示总共1分钟
    }
</script>
</html>